package com.baor.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baor.dao.ScoreConfDao;
import com.baor.dao.VipScoreDao;
import com.baor.domain.conf.ScoreConf;
import com.baor.service.VipScoreService;
import com.baor.utils.AjaxResult;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.Map;

@Service
public class VipScoreServiceImpl implements VipScoreService {

    @Autowired
    private VipScoreDao vipScoreDao;

    @Autowired
    private ScoreConfDao confDao;

    @Override
    public AjaxResult<?> vipScoreUserList(Map<String, Object> params) {
        params.put("pageIndex", (int) params.get("pageSize") * ((int) (params.get("pageIndex")) - 1));
        params.put("pageSize", params.get("pageSize"));
        Map<String, Object> res = new HashMap<>();
        res.put("userList", vipScoreDao.vipScoreUserList(params));
        res.put("pageCount", vipScoreDao.pageCount(params));
        return AjaxResult.success(res);
    }

    @Override
    public AjaxResult<?> conf(ScoreConf conf) {
        confDao.update(conf,new LambdaQueryWrapper<ScoreConf>().eq(ScoreConf::getSiteId,conf.getSiteId()));
        return AjaxResult.success();
    }

    @Override
    public AjaxResult<?> info(Integer siteId) {
        return AjaxResult.success(confDao.selectOne(new LambdaQueryWrapper<ScoreConf>().eq(ScoreConf::getSiteId,siteId)));
    }
}
